package tool.zyk.channel;

import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * author: zyk
 * datetime: 2024/1/25 22:41
 * describe:
 */
@Slf4j
public class ChannelTestClient {
    public static void main(String[] args) throws InterruptedException {
        ChannelFuture channelFuture = new Bootstrap()
                .group(new NioEventLoopGroup())
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel channel) throws Exception {
                        System.out.println("init...");
                        channel.pipeline().addLast(new LoggingHandler(LogLevel.DEBUG));
                    }
                })
                .connect("127.0.0.1", 8081);
        log.warn("channel:{}", channelFuture.channel());
        channelFuture.addListener((ChannelFutureListener) future -> log.warn("channel in listener:{}", future.channel()));
//        channelFuture.sync();
//        log.warn("channel:{}",channelFuture.channel());


    }
}
